<?php
class content extends CI_Controller{
	//构造函数
	function __construct(){
	
		parent::__construct();
		$this->load->helper('url');
		$this->load->helper('form');
		$this->load->model('Content_model',``,TRUE);
		$this->load->library('commonclass');
	}

	function index()
	{
		$id = $this->uri->segment(3);
		$id = intval($id);
		$limit = 5;
		
		$data['content'] = $this->Content_model->get_content($id);
		$data['content'] = $data['content'][0];
		$data['content']['id'] = $id;
		$data['comments'] = $this->Content_model->get_comment($start=0,$limit,$id);
		$data['total'] = $this->Content_model->get_total_comment($id);
		$this->load->view("view_content",$data);
		
	}
	
	
	function add_comment()
	{
		
		$comment_array = $_POST;
		$id =$comment_array['commentid'];
		$id = intval($id);
		$start = 0;
		$limit = 5;
		
		$ip = $this->commonclass->get_IP();

		$n = $this->Content_model->insert_comment($comment_array,$ip);
		
		if ($n)
		{
			$data['comments'] = $this->Content_model->get_comment($start,$limit,$id);
			print_r (json_encode($data['comments']));
			
		}
	}
	
	function get_total_comment()
	{
		$comment_array = $_POST;
		$id =$comment_array['commentid'];
		$total = $comment_array['total'];
		$id = intval($id);
		$total = intval($total);
		$limit = $total;
		$start = 5;
		
		$data['comments'] = $this->Content_model->get_comment($start,$limit,$id);
		print_r (json_encode($data['comments']));
			
	}
}

/* End of content.php */
/* ./application/controllers/content.php */